from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import FilmRowPiece, MoviePieceSeat


@receiver(post_save, sender=FilmRowPiece)
def create_user(sender, instance=None, created=False, **kwargs):
    if created:
        movie_hall = instance.movie_hall
        querysetlist = []
        for i in movie_hall.seats.all():
            # MoviePieceSeat.objects.create(seat=i, movie_piece=instance)
            querysetlist.append(MoviePieceSeat(seat=i,movie_piece=instance))
        MoviePieceSeat.objects.bulk_create(querysetlist)
